{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate the number of looks for InSAR stack processing with ISCE\n",
    "\n",
    "so that the output ground resolutions in azimuth and range direction are similar.\n",
    "\n",
    "One could run the following after unpacking SLCs (to have the metadata) in ISCE tops/stripmapStack workflow."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is the Open Source version of ISCE.\n",
      "Some of the workflows depend on a separate licensed package.\n",
      "To obtain the licensed package, please make a request for ISCE\n",
      "through the website: https://download.jpl.nasa.gov/ops/request/index.cfm.\n",
      "Alternatively, if you are a member, or can become a member of WinSAR\n",
      "you may be able to obtain access to a version of the licensed sofware at\n",
      "https://winsar.unavco.org/software/isce\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import numpy as np\n",
    "from mintpy.utils import isce_utils"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sentinel-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "extract metadata from ISCE/topsStack xml file: /Users/yunjunz/data/test/FernandinaSenDT128/master/IW1.xml\n",
      "near   incidence angle : 30.7791 degree\n",
      "far    incidence angle : 36.5374 degree\n",
      "center incidence angle : 33.6582 degree\n",
      "Azimuth     pixel size : 15.6\n",
      "Azimuth ground spacing : 14.1\n",
      "Azimuth ground spacing : 84.4 after multilooking by 6\n",
      "Range       pixel size : 2.3\n",
      "Range   ground spacing : 4.2\n",
      "Range   ground spacing : 84.1 after multilooking by 20\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(6, 20)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "meta_file = os.path.expandvars('$TEST_DIR/FernandinaSenDT128/master/IW1.xml')\n",
    "isce_utils.resolution2multilook_number(meta_file, resolution=90)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ALOS-1 StripMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/Kirishima/AlosAT424F620_630/isce/masterShelve/data.dat\n",
      "near   incidence angle : 36.5388 degree\n",
      "far    incidence angle : 40.8351 degree\n",
      "center incidence angle : 38.6870 degree\n",
      "Azimuth     pixel size : 3.5\n",
      "Azimuth ground spacing : 3.2\n",
      "Azimuth ground spacing : 28.6 after multilooking by 9\n",
      "Range       pixel size : 4.7\n",
      "Range   ground spacing : 7.5\n",
      "Range   ground spacing : 30.0 after multilooking by 4\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(9, 4)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with $ISCE_STACK/prepRawALOS.py --dual2single/--fbd2fbs\n",
    "meta_file = os.path.expanduser('~/data/Kirishima/AlosAT424F620_630/isce/masterShelve/data.dat')\n",
    "isce_utils.resolution2multilook_number(meta_file, resolution=30)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ALOS-2 StripMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/Kirishima/Alos2AT131F620/isce/masterShelve/data.dat\n",
      "near   incidence angle : 41.1804 degree\n",
      "far    incidence angle : 44.5313 degree\n",
      "center incidence angle : 42.8559 degree\n",
      "Azimuth     pixel size : 2.0\n",
      "Azimuth ground spacing : 1.9\n",
      "Azimuth ground spacing : 20.5 after multilooking by 11\n",
      "Range       pixel size : 1.4\n",
      "Range   ground spacing : 2.1\n",
      "Range   ground spacing : 21.0 after multilooking by 10\n",
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/Kirishima/Alos2AT131F620/isce/masterShelve/data.dat\n",
      "near   incidence angle : 41.1804 degree\n",
      "far    incidence angle : 44.5313 degree\n",
      "center incidence angle : 42.8559 degree\n",
      "Azimuth     pixel size : 2.0\n",
      "Azimuth ground spacing : 1.9\n",
      "Azimuth ground spacing : 18.6 after multilooking by 10\n",
      "Range       pixel size : 1.4\n",
      "Range   ground spacing : 2.1\n",
      "Range   ground spacing : 21.0 after multilooking by 10\n"
     ]
    }
   ],
   "source": [
    "meta_file = os.path.expanduser('~/data/Kirishima/Alos2AT131F620/isce/masterShelve/data.dat')\n",
    "isce_utils.resolution2multilook_number(meta_file, resolution=20)\n",
    "isce_utils.multilook_number2resolution(meta_file, az_looks=10, rg_looks=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ALOS-2 StripMap2 Quad-Pol Beam FP6-7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/JapanAlos2QuadPol/Alos2DT24F2850/stackHH/masterShelve/data.dat\n",
      "near   incidence angle : 37.6301 degree\n",
      "far    incidence angle : 40.3148 degree\n",
      "center incidence angle : 38.9725 degree\n",
      "Azimuth     pixel size : 3.3\n",
      "Azimuth ground spacing : 3.0\n",
      "Azimuth ground spacing : 92.3 after multilooking by 31\n",
      "Range       pixel size : 2.9\n",
      "Range   ground spacing : 4.5\n",
      "Range   ground spacing : 91.0 after multilooking by 20\n",
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/JapanAlos2QuadPol/Alos2DT24F2850/stackHH/masterShelve/data.dat\n",
      "near   incidence angle : 37.6301 degree\n",
      "far    incidence angle : 40.3148 degree\n",
      "center incidence angle : 38.9725 degree\n",
      "Azimuth     pixel size : 3.3\n",
      "Azimuth ground spacing : 3.0\n",
      "Azimuth ground spacing : 89.3 after multilooking by 30\n",
      "Range       pixel size : 2.9\n",
      "Range   ground spacing : 4.5\n",
      "Range   ground spacing : 91.0 after multilooking by 20\n",
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/JapanAlos2QuadPol/Alos2DT18F2890/stackHH/masterShelve/data.dat\n",
      "near   incidence angle : 35.0520 degree\n",
      "far    incidence angle : 37.8800 degree\n",
      "center incidence angle : 36.4660 degree\n",
      "Azimuth     pixel size : 2.9\n",
      "Azimuth ground spacing : 2.7\n",
      "Azimuth ground spacing : 90.8 after multilooking by 34\n",
      "Range       pixel size : 2.9\n",
      "Range   ground spacing : 4.8\n",
      "Range   ground spacing : 91.5 after multilooking by 19\n",
      "extract metadata from ISCE/stripmapStack shelve file: /Users/yunjunz/data/JapanAlos2QuadPol/Alos2DT18F2890/stackHH/masterShelve/data.dat\n",
      "near   incidence angle : 35.0520 degree\n",
      "far    incidence angle : 37.8800 degree\n",
      "center incidence angle : 36.4660 degree\n",
      "Azimuth     pixel size : 2.9\n",
      "Azimuth ground spacing : 2.7\n",
      "Azimuth ground spacing : 93.5 after multilooking by 35\n",
      "Range       pixel size : 2.9\n",
      "Range   ground spacing : 4.8\n",
      "Range   ground spacing : 96.3 after multilooking by 20\n"
     ]
    }
   ],
   "source": [
    "meta_file = os.path.expanduser('~/data/JapanAlos2QuadPol/Alos2DT24F2850/stackHH/masterShelve/data.dat')\n",
    "isce_utils.resolution2multilook_number(meta_file, resolution=90)\n",
    "isce_utils.multilook_number2resolution(meta_file, az_looks=30, rg_looks=20)\n",
    "\n",
    "meta_file = os.path.expanduser('~/data/JapanAlos2QuadPol/Alos2DT18F2890/stackHH/masterShelve/data.dat')\n",
    "isce_utils.resolution2multilook_number(meta_file, resolution=90)\n",
    "isce_utils.multilook_number2resolution(meta_file, az_looks=35, rg_looks=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
